In [2]:
from astropy.io import fits
from astropy.utils.data import download_file

In [3]:
image_file = download_file('http://data.astropy.org/tutorials/FITS-images/HorseHead.fits', cache=True)


Downloading http://chandra.harvard.edu/photo/2013/vela/fits/vela_2.0-8.0_flux.fits [Done]

We can open the fits file by fits.open() and check the info of the fits file by .info()


In [4]:
hdu_list = fits.open(image_file)
hdu_list.info()


Filename: /home/yanyan/.astropy/cache/download/3bc6e348e5bca65cae417559bd2c6b85
No.    Name         Type      Cards   Dimensions   Format
0    PRIMARY     PrimaryHDU     189   (588, 472)   float64   

We get the data by the following command


In [8]:
image_data = hdu_list[0].data
print image_data


[[  3.57891936e-09   8.34289603e-10   0.00000000e+00 ...,   0.00000000e+00
    1.13029266e-08   1.66015553e-08]
 [  0.00000000e+00   9.58613079e-09   6.73792224e-09 ...,   7.05635584e-09
    2.39556844e-09   4.19313275e-10]
 [  3.72970966e-09   7.14046017e-09   6.35789505e-09 ...,   8.96702983e-09
    4.60270655e-09   4.86753610e-09]
 ..., 
 [  1.13655557e-09   3.81179035e-09   3.45669998e-09 ...,   0.00000000e+00
    1.00146203e-09   1.23558768e-08]
 [  0.00000000e+00   2.70082504e-09   1.06594018e-09 ...,   4.79216329e-09
    2.36669205e-09   7.71180067e-09]
 [  4.77691706e-09   8.34896416e-09   6.02902179e-09 ...,   5.10113207e-09
    2.29898113e-09   0.00000000e+00]]

We get the header by the following command


In [10]:
image_header = hdu_list[0].header
print image_header.items


<bound method Header.items of SIMPLE  =                    T / file does conform to FITS standard             
BITPIX  =                  -64 / number of bits per data pixel                  
NAXIS   =                    2 / number of data axes                            
NAXIS1  =                  588 / length of data axis                            
NAXIS2  =                  472 / length of data axis                            
EXTEND  =                    T / FITS dataset may contain extensions            
COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H 
HDUNAME = 'vela_2.0-8.0_flux.fits' / ASCDM block name                           
ASOLFILE= 'pcadf399999303N003_asol1.fits'                                       
THRFILE = 'acisD2005-07-01evtspltN0002.fits'                                    
ORIGIN  = 'ASC     '           / Source of FITS file                            
CREATOR = 'dmimgcalc - Version CIAO 4.4' / tool that created this output        
ASCDSVER= 'CIAO 4.4'           / ASCDS version number                           
MJD_OBS =  5.5021583397856E+04 / Modified Julian date of observation            
DS_IDENT= 'Merged  '           / dataset identifier                             
TLMVER  = 'P009    '           / Telemetry revision number (IP&CL)              
REVISION=                    3 / Processing version of data                     
CHECKSUM= '5aAA8S845YAA5Y53'   / HDU checksum updated 2012-11-07T22:42:04       
DATASUM = '1188128169'         / data unit checksum updated 2012-11-07T22:42:04 
CONTENT = 'EVT2    '           / What data product                              
HDUSPEC = 'ACIS Telemetry Products: Level 0 to ASC Archive ICD Rev 2.11' / ICD r
HDUDOC  = 'ASC-FITS-2.0: McDowell, Rots: ASC FITS File Designers Guide'         
HDUVERS = '1.0.0   '                                                            
HDUCLASS= 'OGIP    '                                                            
HDUCLAS1= 'EVENTS  '                                                            
HDUCLAS2= 'ACCEPTED'                                                            
PIX_ADJ = 'EDSER   '           / Subpixel adjustment algorithm                  
RAND_SKY=  0.0000000000000E+00                                                  
SUBPIXFL= 'acisD1999-07-22subpixN0001.fits'                                     
RAND_PI =  1.0000000000000E+00                                                  
DATE    = '2012-11-07T22:42:04' / Date and time of file creation                
DATE-OBS= '2009-07-09T14:00:05' / Observation start date                        
OBS_MODE= 'POINTING'           / Observation mode                               
DATE-END= '2010-09-05T02:46:25' / Observation end date                          
TIMESYS = 'TT      '           / Time system                                    
MJDREF  =  5.0814000000000E+04 / [d] MJD zero point for times                   
TIMEZERO=  0.0000000000000E+00 / [s] Clock correction                           
TIMEUNIT= 's       '           / Time unit                                      
DATACLAS= 'OBSERVED'           / default                                        
RADESYS = 'ICRS    '           / default                                        
BTIMCORR=  0.0000000000000E+00 / Correction applied to Basic Time rate (s)      
TIMEREF = 'LOCAL   '           / Time reference (barycenter/local)              
TASSIGN = 'SATELLITE'          / Time assigned by clock                         
CLOCKAPP=                    T / default                                        
SIM_X   = -6.8282252473119E-01 / [mm] SIM focus pos                             
SIM_Y   =  0.0000000000000E+00 / [mm] SIM orthogonal axis pos                   
SIM_Z   = -1.9014258036517E+02 / [mm] SIM translation stage pos                 
FOC_LEN =  1.0070000000000E+04 / [mm] HRMA focal length                         
TIERRELA=  1.0000000000000E-09 / default                                        
TIERABSO=  5.0000000000000E-05 / default                                        
TIMVERSN= 'ASC-FITS-2'         / Timing system definition                       
TSTART  =  3.6353520557476E+08 / [s] Observation start time (MET)               
GRATING = 'NONE    '           / Grating                                        
DETNAM  = 'Merged  '           / Detector                                       
RA_TARG =  1.2883625000000E+02 / [deg] Observer's specified target RA           
DEC_TARG= -4.5176583000000E+01 / [deg] Observer's specified target Dec          
DEFOCUS =  1.4449365687057E-03 / [mm] SIM defocus                               
TSTOP   =  4.0004198513585E+08 / [s] Observation end time (MET)                 
STARTOBT=  0.0000000000000E+00 / On-Board MET close to STARTMJF and STARTMNF    
TIMEPIXR=  5.0000000000000E-01 / default                                        
TIMEDEL =  3.2410400000000E+00 / [s] timedel Lev1                               
ACSYS1  = 'CHIP:AXAF-ACIS-1.0' / reference for chip coord system                
ACSYS2  = 'TDET:ACIS-2.2'      / reference for tiled detector coord system      
ACSYS3  = 'DET:ASC-FP-1.1'     / reference for focal plane coord system         
ACSYS4  = 'SKY:ASC-FP-1.1'     / reference for sky coord system                 
GAINFILE= 'acisD2000-01-29gain_ctiN0006.fits'                                   
CTI_CORR=                    T                                                  
CTI_APP = 'PPPPPBPBPP'                                                          
CTIFILE = 'acisD2002-08-01ctiN0007.fits'                                        
MTLFILE = 'acisf12075_000N003_fptemp_egti1.fits'                                
TGAINCOR= 'T       '                                                            
TGAINFIL= 'acisD2010-08-01t_gainN0006.fits'                                     
GRD_FILE= 'acisD1996-11-01gradeN0004.fits'                                      
CORNERS =                    2 / num adjacent side pix > threshold to include co
GRADESYS= 'ASCA    '           / grade system: ASCA, ACIS, or USER              
BPIXFILE= 'acisf12075_000N003_bpix1.fits'                                       
MISSION = 'AXAF    '           / Mission                                        
TELESCOP= 'CHANDRA '           / Telescope                                      
INSTRUME= 'ACIS    '           / Instrument                                     
READMODE= 'TIMED   '           / Read mode                                      
DATAMODE= 'FAINT   '           / Data mode                                      
RUN_ID  =                    1 / Science run index                              
FSW_VERS=                   48 / ACIS flight software version number            
STARTBEP=            315212112 / BEP timer value at TSTART                      
STOPBEP =            253043056 / BEP timer value at TSTOP                       
FEP_ID  =                    0 / Front End Processor ID: 0-5                    
CCD_ID  =                    2 / CCD ID: 0-9                                    
TIMEDELA=  3.2410400000000E+00 / Inferred duration of primary exposure (s)      
TIMEDELB=  0.0000000000000E+00 / Inferred duration of secondary exp. (s)        
FLSHTIME=  0.0000000000000E+00 / [s]                                            
EXPTIME =  3.2000000000000E+00 / [s]                                            
DTYCYCLE=                    0                                                  
FIRSTROW=                    1 / Index of first row of CCD (sub)array readout   
NROWS   =                 1024 / Number of rows in (sub)array readout           
FLSHTIMA=  0.0000000000000E+00 / Inferred duration of flush before primary fram 
FLSHTIMB=  0.0000000000000E+00 / Inferred duration of flush before secondary fr 
CYCLE   = 'P       '           / events from which exps? Prim/Second/Both       
HISTNUM =                  632                                                  
TITLE   = 'The Unique Dynamical Vela Pulsar Wind Nebula' / Proposal title       
OBSERVER= 'Dr. George Pavlov'  / Principal investigator                         
OBJECT  = 'Vela PWN'           / Source name                                    
OBS_ID  = 'Merged  '           / Observation id                                 
SEQ_NUM = 'Merged  '           / Sequence number                                
ONTIME  =  8.8108228969980E+05 / [s] Sum of GTIs                                
ONTIME7 =  4.4054114484990E+05 / [s] Sum of GTIs                                
ONTIME2 =  0.0000000000000E+00 / [s] Sum of GTIs                                
ONTIME5 =  0.0000000000000E+00 / [s] Sum of GTIs                                
ONTIME6 =  0.0000000000000E+00 / [s] Sum of GTIs                                
ONTIME3 =  0.0000000000000E+00 / [s] Sum of GTIs                                
ONTIME8 =  0.0000000000000E+00 / [s] Sum of GTIs                                
LIVETIME=  8.6992549522356E+05 / [s] Livetime                                   
LIVTIME7=  4.3496274761178E+05 / [s] Livetime                                   
LIVTIME2=  0.0000000000000E+00 / [s] Livetime                                   
LIVTIME5=  0.0000000000000E+00 / [s] Livetime                                   
LIVTIME6=  0.0000000000000E+00 / [s] Livetime                                   
LIVTIME3=  0.0000000000000E+00 / [s] Livetime                                   
LIVTIME8=  0.0000000000000E+00 / [s] Livetime                                   
EXPOSURE=  4.3497374761178E+05 / [s] Exposure time                              
EXPOSUR7=  4.3496274761178E+05 / [s] Exposure time                              
EXPOSUR2=  0.0000000000000E+00 / [s] Exposure time                              
EXPOSUR5=  0.0000000000000E+00 / [s] Exposure time                              
EXPOSUR6=  0.0000000000000E+00 / [s] Exposure time                              
EXPOSUR3=  0.0000000000000E+00 / [s] Exposure time                              
EXPOSUR8=  0.0000000000000E+00 / [s] Exposure time                              
DTCOR   =  9.8733739787229E-01 / Dead time correction                           
ASPTYPE = 'KALMAN  '                                                            
BIASFIL2= 'acisf399998116N003_0_bias0.fits' / bias file used: CCD 2             
BIASFIL7= 'acisf399998116N003_1_bias0.fits' / bias file used: CCD 7             
BIASFIL5= 'acisf399998116N003_2_bias0.fits' / bias file used: CCD 5             
FP_TEMP =  1.5344601440000E+02 / [K] Focal Plane Temperature                    
BIASFIL6= 'acisf399998116N003_3_bias0.fits' / bias file used: CCD 6             
BIASFIL3= 'acisf399998116N003_4_bias0.fits' / bias file used: CCD 3             
BIASFIL8= 'acisf399998116N003_5_bias0.fits' / bias file used: CCD 8             
AIMPFILE= 'telD1999-07-23aimptsN0002.fits'                                      
GEOMFILE= 'telD1999-07-23geomN0006.fits'                                        
SKYFILE = 'telD1999-07-23skyN0002.fits'                                         
TDETFILE= 'telD1999-07-23tdetN0001.fits'                                        
SHELLFIL= 'telD1999-07-23sgeomN0001.fits'                                       
FLTFILE = 'acisf12075_000N003_flt1.fits'                                        
MASKFILE= 'acisf12075_000N003_msk1.fits'                                        
PBKFILE = 'acisf399999425N003_pbk0.fits'                                        
DY_AVG  =  8.6558815057000E-01 / [mm] Mean DY during observation                
DZ_AVG  =  9.1717584578000E-01 / [mm] Mean DZ during observation                
DTH_AVG = -3.0294623866000E-03 / [deg] Mean DTHETA during observation           
OCLKPAIR=                    8 / # of pairs of overclock pixels per output      
ORC_MODE=                    0 / Output register clocking mode                  
SUM_2X2 =                    0 / On-chip summing. 0:None; 1:Sum 2x2             
FEP_CCD = '275638  '           / CCD to FEPID mapping, fep0 is left most digit  
CALDBVER= '4.5.0   '                                                            
WCSTY1P = 'PHYSICAL'                                                            
WCSTY2P = 'PHYSICAL'                                                            
HISTORY  TOOL  :dmimgcalc   2012-11-07T22:42:04                         ASC00622
HISTORY  PARM  :infile=vela_2.0-8.0_image_clean.fits                    ASC00623
HISTORY  PARM  :infile2=vela_5.0_image_expmap.fits                      ASC00624
HISTORY  PARM  :outfile=vela_2.0-8.0_flux.fits                          ASC00625
HISTORY  PARM  :operation=div                                           ASC00626
HISTORY  PARM  :weight=1                                                ASC00627
HISTORY  PARM  :weight2=1                                               ASC00628
HISTORY  PARM  :lookupTab=/Users/depasq/LocalApps/ciao-4.4/data/dmmerge_ASC00629
HISTORY  CONT  :header_lookup.txt                                       ASC00630
HISTORY  PARM  :clobber=yes                                             ASC00631
HISTORY  PARM  :verbose=0                                               ASC00632
MTYPE1  = 'SKY     '           / DM Keyword: Descriptor name.                   
MFORM1  = 'X,Y     '           / DM Keyword: Descriptor value.                  
CTYPE1P = 'X       '                                                            
CRVAL1P =  3.9572430458512E+03                                                  
CRPIX1P =  2.9400000000000E+02                                                  
CDELT1P =  1.0000000000000E+00                                                  
LTV1    = -3.6632430458512E+03                                                  
LTM1_1  =  1.0000000000000E+00                                                  
CTYPE2P = 'Y       '                                                            
CRVAL2P =  4.1919555257836E+03                                                  
CRPIX2P =  2.3600000000000E+02                                                  
CDELT2P =  1.0000000000000E+00                                                  
LTV2    = -3.9559555257836E+03                                                  
LTM2_2  =  1.0000000000000E+00                                                  
MTYPE2  = 'EQPOS   '           / DM Keyword: Descriptor name.                   
MFORM2  = 'RA,DEC  '           / [degree]                                       
CTYPE1  = 'RA---TAN'                                                            
CRVAL1  =  1.2882334000000E+02                                                  
CRPIX1  =  2.9400000000000E+02                                                  
CDELT1  = -1.3666666666667E-04                                                  
CUNIT1  = 'degree  '                                                            
CTYPE2  = 'DEC--TAN'                                                            
CRVAL2  = -4.5176306000000E+01                                                  
CRPIX2  =  2.3600000000000E+02                                                  
CDELT2  =  1.3666666666667E-04                                                  
CUNIT2  = 'degree  '                                                            >

We can get individual header items by calling it as dictionary


In [12]:
print image_header['CRVAL1']
print image_header['CRVAL2']


128.82334
-45.176306

In [ ]: